﻿using System;
using Game1942.Library.Background;
using Game1942.Library.Background.Bodies;
using Game1942.Library.FlightPlans;
using Game1942.Library.Items;
using Game1942.Library.Weapons;

namespace Game1942.Library.Planes
{
    public class Bomber : Aircraft
    {
        public Bomber()
        {
            energy = new EnergyCounter(Constants.Bomber.Energy);
            damage = Constants.Bomber.Damage;
            score = Constants.Bomber.Score;
            manageTurn = new TurnManager(Constants.Bomber.Speed, Constants.Bomber.Rate);
            playerTeam = Constants.Bomber.PlayerTeam;

            flightPlan = new ZigZagStrategy(Constants.Bomber.Speed, Constants.ZigZagStrategy.Cycle);

            position.SetBody(new Square(Constants.Bomber.Width, Constants.Bomber.Height));
        }

        public Bomber(Point value) : this()
        {
            base.SetPosition(value);
        }

        public override void Shoot()
        {

            switch (new Random().Next(3))
            {
                case 0:
                    {
                        var laser = new Laser(new Point(ActualPosition.X + 30,ActualPosition.Y + 90),playerTeam);
                        Driver.Instance.AddLiveUnit(laser, Constants.Laser.Width, Constants.Laser.Height,Constants.Laser.ViewNameDown);
                        break;
                    }
                case 1:
                    {
                        var rocket = new Rocket(new Point(ActualPosition.X + 30, ActualPosition.Y + 90),playerTeam);
                        Driver.Instance.AddLiveUnit(rocket, Constants.Rocket.Width, Constants.Rocket.Height, Constants.Rocket.ViewNameDown); 
                        break;
                    }
                case 2:
                    {
                        var torpedo = new Torpedo(new Point(ActualPosition.X + 30, ActualPosition.Y + 90),playerTeam, true);
                        Driver.Instance.AddLiveUnit(torpedo, Constants.Torpedo.Width, Constants.Torpedo.Height, Constants.Torpedo.ViewNameDown); 
                        break;
                    }
            }
        }
        public override void Destroy()
        {
            position.Deallocate();  // If it is on the map, get rid of it
            Alive = false;
            Driver.Instance.AddLiveUnit(new AmmoPackage(position.Value),Constants.AmmoPackage.Width,Constants.AmmoPackage.Height,
                Constants.AmmoPackage.ViewName);
        }
    }
}
